package com.system.cofig;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfiguration {
    @Value("${spring.application.name}")
    private String appName;
    @Value("${server.port}")
    private String port;

    //配置swagger的Docket的bean实例
    @Bean("systemApi")
    @Order(2)
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //注意basePackage改成自己每个项目的路径
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    //配置swagger信息
    private ApiInfo apiInfo() {
        Contact contact = new Contact("hujunwei", "", "1149088509@qq.com");
        return new ApiInfoBuilder()
                .title(appName+"服务接口文档")
                .description("<div style='font-size:14px;color:red;'>本文档包含"+appName+"系统的所有接口及接口描述，支持在线调试。</div>")
                .termsOfServiceUrl("http://localhost:"+port)
                .contact(contact)
                .version("1.0")
                .build();
    }
}
